package com.tcl.feign.controller;

import com.tcl.api.request.UserAddRequest;
import com.tcl.api.response.ResultMsg;
import com.tcl.api.response.UserResponse;
import com.tcl.feign.feign.UserServiceFeignClient02;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/demo02")
public class DemoController02 {

    @Autowired
    private UserServiceFeignClient02 userServiceFeignClient;


    @GetMapping("/get")
    public UserResponse get(@RequestParam("id") Integer id) {
        return userServiceFeignClient.get(id);
    }

    @PostMapping("/get2")
    public UserResponse get2(@RequestParam("id") Integer id) {
        return userServiceFeignClient.get2(id);
    }

    @GetMapping("/get3")
    public ResultMsg get3(@RequestParam("id") Integer id) {
        return userServiceFeignClient.get3(id);
    }

    //===============================================================
    @GetMapping("/list")
    public List<UserResponse> list(@RequestParam(value = "name") String name, @RequestParam(value = "gender") Integer gender) {
        return userServiceFeignClient.list(name, gender);
    }

    @GetMapping("/list2")
    public List<UserResponse> list2(UserAddRequest request) {
        return userServiceFeignClient.list2(request);
    }


    //===============================================================
    @PostMapping("/add")
    public Integer add(@RequestBody UserAddRequest request) {
        return userServiceFeignClient.add(request);
    }

    @PostMapping("/add2")
    public Integer add2(UserAddRequest request) {
        return userServiceFeignClient.add2(request);
    }


    //============================异常测试=================
    @GetMapping("/error")
    public ResultMsg error(@RequestParam("id") Integer id) {
        return userServiceFeignClient.error(id);
    }


}
